package com.ossjk.qlh.specializedSubject.controller;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ossjk.core.base.controller.BaseController;
import com.ossjk.core.vo.ResponseBean;
import com.ossjk.qlh.specializedSubject.entity.Course;
import com.ossjk.qlh.specializedSubject.entity.Subject;
import com.ossjk.qlh.specializedSubject.service.ICourseService;
import com.ossjk.qlh.specializedSubject.service.ISubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * Copyright  2023-03-07 QLH. Tech Ltd. All rights reserved.
 * 
 * @Package: com.ossjk.qlh.specializedSubject.controller
 * @ClassName: CourseController
 * @Description: Course-控制器
 * @author: Levi
 * @date:  2023-03-07 10:19:53 
 */
@Api(tags = "课程")
@RestController
@RequestMapping("/specializedSubject/course")
public class CourseController extends BaseController {
	
	@Autowired
	private ICourseService iCourseService;

	@Autowired
	private ISubjectService iSubjectService;

	@ApiOperation(value = "列表")
	@RequiresPermissions("00050020")
	@GetMapping("/list")
	public ResponseBean<Page<Course>> list(Page page) {
		QueryWrapper<Course> queryWrapper = new QueryWrapper<Course>();

		return ResponseBean.Success(iCourseService.page(page,queryWrapper));
	}
	@ApiOperation(value = "列表")
	@RequiresPermissions("00050020")
	@GetMapping("/getlist")
	public ResponseBean<List<Subject>> list(){
		QueryWrapper<Subject> queryWrapper = new QueryWrapper<Subject>();
		return  ResponseBean.Success(iSubjectService.list(queryWrapper));
	}


	@ApiOperation(value = "添加")
	@RequiresPermissions("")
	@PostMapping("/save")
	public ResponseBean save(@RequestBody Course record) {
		if (iCourseService.save(record)) {
			return ResponseBean.Success();
		} else {
			return ResponseBean.Fail();
		}
	}

	@ApiOperation(value = "去编辑")
	@RequiresPermissions("")
	@GetMapping("/toUpdate")
	public ResponseBean<Course> toUpdate(@ApiParam(value = "id") @RequestParam(name = "id") String id) {
		Course course = iCourseService.getById(id);
		if (ObjectUtil.isNotNull(course)) {
			return ResponseBean.Success(course);
		} else {
			return ResponseBean.Fail();
		}
	}


	@ApiOperation(value = "编辑")
	@RequiresPermissions("")
	@PutMapping("/update")
	public ResponseBean update(@RequestBody Course record) {
		if (iCourseService.updateById(record)) {
			return ResponseBean.Success();
		} else {
			return ResponseBean.Fail();
		}
	}

	@ApiOperation(value = "删除")
	@RequiresPermissions("")
	@DeleteMapping("/remove")
	public ResponseBean remove(@ApiParam(value = "ids") @RequestParam(name = "ids") String[] ids) {
		if (iCourseService.removeByIds(Arrays.asList(ids))) {
			return ResponseBean.Success();
		} else {
			return ResponseBean.Fail();
		}
	}
}
